﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChoicePers_List.aspx.cs" Inherits="Common_ChoicePers_List" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>显示人员</title>
    <link href="../CSS/css.CSS" type="text/css" rel="stylesheet" />
    <script language ="javascript" type ="text/javascript" >
    function ChoicePer(obj)
    {
        //ID的集合
        var sPersIDInfo   = parent.RightFrameDown.form1.PersIDInfo.value;    
        var sPersNameInfo = parent.RightFrameDown.form1.PersNameInfo.value;
        var sBack = "";
        if(obj.checked)
        {
           sBack = DelRepeatData(sPersIDInfo,sPersNameInfo,obj.value,"1");
        }
        else
        {
           sBack = DelRepeatData(sPersIDInfo,sPersNameInfo,obj.value,"0");
        }  
        
        var aBack = sBack.split('|');
        
        parent.RightFrameDown.form1.PersIDInfo.value   = aBack[0];
        parent.RightFrameDown.form1.POPIDCol.value     = aBack[0] ;
        
        parent.RightFrameDown.form1.PersNameInfo.value = aBack[1];
        parent.RightFrameDown.form1.POPNameCol.value   = aBack[1] ; 
        
//	    var sDelPersID   ="";  //人员ID 
//        var sDelPersID2   ="";  //人员ID 
//	    var sDelPersName = "";  //人员名称
//	    var sDelPersName2 = "";  //人员名称
//	    
//        var aPers = obj.value.split(',');
//        if(parent.RightFrameDown.form1.PersIDInfo.value != "")
//        {
//            var astr = parent.RightFrameDown.form1.PersIDInfo.value.split(',');
//            if(astr.length=="1")
//            {
//                var sDelPersID   = aPers[0];  //人员ID 	        
//	            var sDelPersName = aPers[1];  //人员名称
//            }
//            else
//            {
//                var sDelPersID   = "," + aPers[0];  //人员ID 	        
//	            var sDelPersID2   = aPers[0] + ",";  //人员ID 
//	            var sDelPersName = "," + aPers[1];  //人员名称
//	            var sDelPersName2 = aPers[1] + ",";  //人员名称
//	        }
//	        
//	        var sPersID   = "," + aPers[0];  //人员ID 
//	        var sPersName = "," + aPers[1];  //人员名称
//        }
//        else
//        {
//            var sPersID   = aPers[0];  //人员ID 
//	        var sPersName = aPers[1];  //人员名称
//	        var sDelPersID   = aPers[0];  //人员ID 
//	        var sDelPersName = aPers[1];  //人员名称
//        }
//        //debugger;
//        if(obj.checked)
//        {
//           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID,"");
//           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID2,"");
//           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value + sPersID ;
//           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName,"");
//           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName2,"");
//           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value + sPersName ;
//        }
//        else
//        {
//            parent.RightFrameDown.form1.PersIDInfo.value   = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID,"");
//            parent.RightFrameDown.form1.PersIDInfo.value   = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID2,"");
//            parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName,"");
//            parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName2,"");
//        }        
//        parent.RightFrameDown.form1.POPIDCol.value = parent.RightFrameDown.form1.PersIDInfo.value;
//        parent.RightFrameDown.form1.POPNameCol.value = parent.RightFrameDown.form1.PersNameInfo.value;
	}
	
	function ChoiceAllPer(obj)
    {
        var iPersNum = form1.PersCount.value;
        if(obj.checked)
        {           
           for(i=0;i<iPersNum;i++)
            {
                if(iPersNum=="1")
                {
                    var PersValue = document.all.PersCK.value;
                    document.all.PersCK.checked = true;
                    //alert(PersValue);
                    IfChoicePer(PersValue,"1");
                }
                else
                {
                    var PersValue = document.all.PersCK[i].value;
                    document.all.PersCK[i].checked = true;
                    //alert(PersValue);
                    IfChoicePer(PersValue,"1");
                }
            }
        }
        else
        {
            for(i=0;i<iPersNum;i++)
            {
                if(iPersNum=="1")
                {
                    var PersValue = document.all.PersCK.value;
                    document.all.PersCK.checked = false; 
                    IfChoicePer(PersValue,"0");                     
                    //alert(PersValue);
                }
                else
                {
                    var PersValue = document.all.PersCK[i].value;
                    document.all.PersCK[i].checked = false;
                    IfChoicePer(PersValue,"0");
                    //alert(PersValue);
                }
            }
        }
    }
    
    
    function IfChoicePer(obj,type)
    {
	    /*var sDelPersID   ="";  //人员ID 
        var sDelPersID2   ="";  //人员ID 
	    var sDelPersName = "";  //人员名称
	    var sDelPersName2 = "";  //人员名称
	    
        var aPers = obj.split(',');
        if(parent.RightFrameDown.form1.PersIDInfo.value != "")
        {
            var astr = parent.RightFrameDown.form1.PersIDInfo.value.split(',');
            if(astr.length=="1")
            {
                var sDelPersID   = aPers[0];  //人员ID 	        
	            var sDelPersName = aPers[1];  //人员名称
            }
            else
            {
                var sDelPersID   = "," + aPers[0];  //人员ID 	        
	            var sDelPersID2   = aPers[0] + ",";  //人员ID 
	            var sDelPersName = "," + aPers[1];  //人员名称
	            var sDelPersName2 = aPers[1] + ",";  //人员名称
	        }
	        
	        var sPersID   = "," + aPers[0];  //人员ID 
	        var sPersName = "," + aPers[1];  //人员名称
        }
        else
        {
            var sPersID   = aPers[0];  //人员ID 
	        var sPersName = aPers[1];  //人员名称
	        var sDelPersID   = aPers[0];  //人员ID 
	        var sDelPersName = aPers[1];  //人员名称
        }
        //debugger;
        if(type == "1")
        {
           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID,"");
           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID2,"");
           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value + sPersID ;
           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName,"");
           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName2,"");
           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value + sPersName ;
        }
        else
        {
            parent.RightFrameDown.form1.PersIDInfo.value   = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID,"");
            parent.RightFrameDown.form1.PersIDInfo.value   = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID2,"");
            parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName,"");
            parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName2,"");
        }
        parent.RightFrameDown.form1.POPIDCol.value = parent.RightFrameDown.form1.PersIDInfo.value;
        parent.RightFrameDown.form1.POPNameCol.value = parent.RightFrameDown.form1.PersNameInfo.value;
        */
        
        //ID的集合        
        var sPersIDInfo   = parent.RightFrameDown.form1.PersIDInfo.value;    
        var sPersNameInfo = parent.RightFrameDown.form1.PersNameInfo.value;
        
        var sBack = DelRepeatData(sPersIDInfo,sPersNameInfo,obj,type);
        var aBack = sBack.split('|');
        
        parent.RightFrameDown.form1.PersIDInfo.value   = aBack[0];
        parent.RightFrameDown.form1.POPIDCol.value     = aBack[0] ;
        
        parent.RightFrameDown.form1.PersNameInfo.value = aBack[1];
        parent.RightFrameDown.form1.POPNameCol.value   = aBack[1] ; 
	}
	
	
	//去掉重复的数据sData:字符串 sID:比较的ID
    function  DelRepeatData(sID,sName,sObj,Ifchecked)
    {
       var sBack="";
       var sIDCol="";
       var sNameCol="";
       var aObj = sObj.split(',');
       if(sID != "")
       {
           var aryName = sName.split(',');
           var ary = sID.split(',');
           var iary = ary.length;
           for(x=0;x<ary.length;x++)
           {
               if(ary[x] !=aObj[0])
               {
                   if(x!=0 && sIDCol !="")
                   {
                       sIDCol   = sIDCol + ",";
                       sNameCol = sNameCol + ",";
                   }
                   sIDCol   = sIDCol + ary[x];
                   sNameCol = sNameCol + aryName[x];                   
               }               
           }
       }
       if(Ifchecked == "1")
       {
           if(sIDCol == "")
           {
               sIDCol   = sIDCol   + aObj[0];
               sNameCol = sNameCol + aObj[1];
           }
           else
           {
               sIDCol   = sIDCol   + ","+ aObj[0];
               sNameCol = sNameCol + ","+ aObj[1];
           }
       }
       
       sBack    = sIDCol +"|"+ sNameCol ;
       return sBack
    }
    
  </script>
</head>
<body>
    <form id="form1" runat="server">    
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr style ="height :30px;">
       <td><asp:Label ID="OrgName" runat ="server" ></asp:Label></td>
    </tr>
    <tr>
      <td>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="table">
          <%=sHtml%>
        </table>   
      </td>
    </tr>
    </table>
    <input type="hidden" id="PersCount" runat ="server"  />
    </form>
    
    <script language ="javascript" type ="text/javascript" >
        //parent.RightFrameDown.form1.PersIDInfo.value =  parent.RightFrameDown.form1.POPIDCol.value ;  //人员ID初始化
        //parent.RightFrameDown.form1.PersNameInfo.value =  parent.RightFrameDown.form1.POPNameCol.value ;  //人员Name初始化
        //debugger;
        var iPersNum = form1.PersCount.value*1;       
        //人员ID的赋值
        for(i=0;i<iPersNum;i++)
        {
            if(iPersNum=="1")
            {
                var PersValue = document.all.PersCK.value;
                var PersAry = PersValue.split(',');
                
                var aPersID = parent.RightFrameDown.form1.POPIDCol.value.split(',');
                var iPersID = aPersID.length;
                for(k=0;k<iPersID;k++)
                {
                    if(aPersID[k]==PersAry[0])
                    {
                       document.all.PersCK.checked = true;
                       break;
                    }
                }
            }
            else
            {
                var PersValue = document.all.PersCK[i].value;
                var PersAry = PersValue.split(',');
                if(typeof parent.RightFrameDown.form1 !='undefined')
                {
                    var aPersID = parent.RightFrameDown.form1.POPIDCol.value.split(',');
                    var iPersID = aPersID.length;
                    for(k=0;k<iPersID;k++)
                    {
                        if(aPersID[k]==PersAry[0])
                        {
                           document.all.PersCK[i].checked = true;
                           break;
                        }
                    }
                }
            }
        }
     </script>
</body>
</html>
